<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>带背景的文本</title>
</head>

<body>


    .bg {
    font-size: 100px;
    color: transparent;
    background: linear-gradient(45deg, #0d0c0d, #cdc547, #158cc7);
    background-clip: text;
    -webkit-background-clip: text;
    }


    .bg-div {
    font-size: 100px;
    color: transparent;
    background: url("https://www.eveningwater.com/img/segmentfault/3.png") no-repeat center center;
    background-size: cover;
    background-clip: text;
    -webkit-background-clip: text;
    }
    </style>
    <div class="bg">我是彩色背景的文字</div>
    <div class="bg-div">我是图片背景的文字</div>


    <p class="border-box">The background extends behind the border.</p>
    <p class="padding-box">The background extends to the inside edge of the border.</p>
    <p class="content-box">The background extends only to the edge of the content box.</p>
    <p class="text">The background is clipped to the foreground text.</p>
    <style>
        p {
            border: .8em darkviolet;
            border-style: dotted double;
            margin: 1em 0;
            padding: 1.4em;
            background: linear-gradient(60deg, red, yellow, red, yellow, red);
            font: 900 1.2em sans-serif;
            text-decoration: underline;
        }

        .border-box {
            background-clip: border-box;
        }

        .padding-box {
            background-clip: padding-box;
        }

        .content-box {
            background-clip: content-box;
        }

        .text {
            background-clip: text;
            -webkit-background-clip: text;
            color: rgba(0, 0, 0, .2);
        }
    </style>

</body>

</html>
<style>